const express = require('express');
const path = require('path');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

app.use(express.static(path.join(__dirname, '/dist')));
app.use(
  createProxyMiddleware('/api', {
    target: 'http://39.101.73.221:8083',
    secure: false,
    changeOrigin: true,
    pathRewrite: {
      '^/api/sMQcode': '/api/mcode',
      '^/api/queryQcode': '/api/queryToken',
      '^/api/login': '/api/login',
      '^/api/logout': '/api/logout',
      '^/api/mList': '/api/alarmPlatFormData',
      '^/api/delete': '/api/delAlarmPlatFormData',
      '^/api/deviceInfo': '/api/deviceInfoList',
      '^/api/delDeviceInfo': '/api/delDeviceInfo',
      '^/api/userList': '/api/userList',
      '^/api/roleList': '/api/roleList',
      '^/api/updateUser': '/api/updateUserInfo',
      '^/api/sysncUser': '/api/syncAccount',
      '^/api/deviceNumber': '/api/deviceNumber',
      '^/api/getSpeedNum': '/api/expendTimeDashboard',
      '^/api/getDomainList': '/api/cloudDomainList',
      '^/api/syncDomain': '/api/syncCloudDomain',
      '^/api/delDomain': '/api/delClouddomain',
      '^/api/dnsList': '/api/cloudDomainEdit',
      '^/api/cUsers': '/api/currentUser',
      '^/api/app/jobAdd': '/api/app/job/add',
      '^/api/app/jobList': '/api/app/job/list',
      '^/api/app/jobOper': '/api/app/job/oper',
      '^/api/indexList': '/api/index/list',
      '^/api/indexRemove': '/api/index/remove',
      '^/api/indexBackup': '/api/index/backup',
      '^/api/indexDetail': '/api/index/detail',
      '^/api/indexSync': '/api/index/sync',
      '^/api/indexDelBatchES': '/api/index/delBatchES',
      '^/api/hive/indexPageList': '/api/hive/index/pageList',
      '^/api/app/job/logList': '/api/app/job/log/list',
      '^/api/qz/logRemove': '/api/qz/log/remove',
      '^/api/qz/logRemoveBatch': '/api/qz/log/removeBatch',
      '^/api/pro/indexList': '/api/index/list',
      '^/api/pro/indexRemove': '/api/index/remove',
      '^/api/pro/indexBackup': '/api/index/backup',
      '^/api/pro/indexDetail': '/api/index/detail',
      '^/api/pro/indexSync': '/api/index/sync',
      '^/api/pro/hive/indexPageList': '/api/hive/index/pageList',
      '^/api/indexOperESStatus': '/api/index/operESStatus',
      '^/api/chart/info': '/api/chart/info',
      '^/api/local/jobAdd': '/api/local/job/add',
      '^/api/local/jobList': '/api/local/job/list',
      '^/api/local/jobOper': '/api/local/job/oper',
      '^/api/index/backupAll': '/api/index/backup/all',
      '^/api/getVMAlarmInfos': '/api/getVMAlarmInfos',
      '^/api/updateThreshold': '/api/updateThreshold',
      '^/api/syncVMIds': '/api/syncVMIds',
      '^/api/quickLogin': '/api/quickLogin',
      '^/api/quickLogin/callBack': '/api/quickLogin/callBack',
      '^/api/quickLogin/dynamicToken': '/api/quickLogin/dynamicToken',
      '^/api/quickLoginList': '/api/quickLoginList',
    },
  }),
);
app.get('*', (req, res) => {
  res.sendFile(path.join(`${__dirname}/dist/index.html`));
});
const port = process.env.PORT || 3000;
app.listen(port);
console.log(`App is listening on port ${port}`);
